<template>
  <page-meta :root-font-size="fontsize" style="display: block">
    <div class="login">
      <!-- <xlNavBar title=" " :showLeft="false" :isMark="false" bgc="transparent"></xlNavBar> -->
      <image class="image" src="https://canyinxinxi.cn/dist_img/WechatIMG5147.jpg" mode="scaleToFill" />
      <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机快捷登录</button>
      <div class="back" @click="back">返回上一页</div>
      <div class="login_ts">登录后您将获得以下权益</div>
      <div class="bottom">
        <div class="item" v-for="item in list" :key="item.name">
          <image :src="item.icon" mode="scaleToFill" />
          <div class="name">{{ item.name }}</div>
        </div>
      </div>
    </div>
  </page-meta>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
export default {
  name: "login",
  components: {},
  props: {},
  data() {
    return {
      fontsize: "",
      code: "",
      device_model: "",
      list: [
        {
          name: "免费发布",
          icon: "https://chenxiao.obs.cn-north-1.myhuaweicloud.com/img/46_1682257410066545929.hOZuCAZrUU6P536b34a7f5447a6a3ae1ecf71a4c0ff1.png",
        },
        {
          name: "优质信息",
          icon: "https://chenxiao.obs.cn-north-1.myhuaweicloud.com/img/46_1682257429657692765.VPu1QKv1bKqv9112b853a7a3bfbfe64ace5a63ceade2.png",
        },
        {
          name: "快速联系",
          icon: "https://chenxiao.obs.cn-north-1.myhuaweicloud.com/img/46_1682257445611906178.pTbmk1qb78jX5823256ad732985b4be64adcbe5d89f1.png",
        },
        {
          name: "专属特权",
          icon: "https://chenxiao.obs.cn-north-1.myhuaweicloud.com/img/46_1682257461389508879.sY765PNPyOzt6526a2d269eed35e53d6035cbf8c3f06.png",
        },
      ],
    };
  },
  computed: { ...mapGetters("user", ["getUserInfo", "getUserStatus"]) },
  methods: {
    ...mapActions("user", ["setUserInfo", "setStatus", "chatLogin"]),
    async getPhoneNumber(e) {
      let _this = this;
      this.$throttle(async () => {
        if (e.detail.errMsg === "getPhoneNumber:ok") {
          let res = await _this.chatLogin({ code: e.detail.code, deviceModel: this.device_model, type: "back" });
          if (res) {
            _this.isLogin = true;
            _this.phone = res.phone;
            _this.setStatus();
            setTimeout(() => {
              _this.$back();
            }, 500);
          }
        } else {
          //如果没有走以上，均为点击了拒绝授权
          console.log("用户拒绝授权");
          uni.showToast({
            title: "登录授权已取消",
            icon: "error",
            mask: true,
          });
          // 通常会在这里弹出模态框，引导用户点击允许授权
        }
      });
    },
    back() {
      this.$back();
    },
  },
  watch: {},
  // 页面周期函数--监听页面加载
  onLoad() {
    let designWidth = 37.5; //因设计图的宽度
    let that = this;
    //窗体改变大小触发事件
    uni.onWindowResize(res => {
      console.log("变化后的窗口宽度=", res.size.windowWidth);
      //100*屏幕宽度/设计稿宽度
      that.fontsize = Math.floor((1.5 * res.size.windowWidth) / designWidth) + "px";

      console.log("字体大小：", that.fontsize);
    });

    //打开获取屏幕大小
    uni.getSystemInfo({
      success(res) {
        console.log("设备信息：", res);
        that.fontsize = Math.floor((1.5 * res.screenWidth) / designWidth) + "px";
        that.device_model = res.device_model;
        console.log("字体大小：", that.fontsize);
      },
    });
  },
  // 页面周期函数--监听页面初次渲染完成
  onReady() {},
  // 页面周期函数--监听页面显示(not-nvue)
  onShow() {},
  // 页面周期函数--监听页面隐藏
  onHide() {},
  // 页面周期函数--监听页面卸载
  onUnload() {},
  // 页面处理函数--监听用户下拉动作
  // onPullDownRefresh() { uni.stopPullDownRefresh(); },
  // 页面处理函数--监听用户上拉触底
  // onReachBottom() {},
  // 页面处理函数--监听页面滚动(not-nvue)
  // onPageScroll(event) {},
  // 页面处理函数--用户点击右上角分享
  // onShareAppMessage(options) {},
};
</script>

<style scoped lang="scss">
.login {
  width: 100%;
  height: 100vh;
  .image {
    width: 100%;
    height: 60%;
    // margin-bottom: 35px;
  }
  button,
  uni-button {
    width: 80%;
    height: 50px;
    background: #43be1e;
    border-radius: 25px 25px 25px 25px;
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
  }
  .back {
    width: 100%;
    text-align: center;
    margin: 20px auto 21px;
    font-size: 16px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
  }
  .login_ts {
    width: 100%;
    text-align: center;
    font-size: 12px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 400;
    color: #999999;
  }
  .bottom {
    display: flex;
    justify-content: space-around;
    width: 80%;
    text-align: center;
    margin: 15px auto 0;
    .item {
      image,
      uni-image {
        width: 40px;
        height: 40px;
      }
      .name {
        font-size: 12px;
        font-weight: 400;
        color: #333333;
      }
    }
  }
}
</style>
